<?php
require(__META_CONTROLS_GEN__ . '/CompetitorMetaControlGen.class.php');

/**
 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
 * and QControls to perform the Create, Edit, and Delete functionality of the
 * Competitor class.  This code-generated class extends from
 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
 * display an HTML form that can manipulate a single Competitor object.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create a new QForm or QPanel which instantiates a CompetitorMetaControl
 * class.
 *
 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
 * or overwrite this file.
 *
 * @package My QCubed Application
 * @subpackage MetaControls
 */
class CompetitorMetaControl extends CompetitorMetaControlGen {
    private $txtACompetitor;

    private $dttTime;

    public function txtACompetitor_Create($strControlId = null) {
        $this->txtACompetitor = new QAjaxAutoCompleteTextBox($this->objParentObject, 'txtACompetitor_Change',$strControlId);
        $this->txtACompetitor->Name = QApplication::Translate('Competitor');
        $this->txtACompetitor->MustMatch=true;
        if($this->objCompetitor->CompetitorId) $this->txtACompetitor->Text = $this->objCompetitor->CompetitorId->__toString();
        $this->txtACompetitor->MaxLength = Org::NameMaxLength;
        return $this->txtACompetitor;
    }
    public function calDate_Create($strControlId = null) {
        $this->calDate = new QCalendarPopup($this->objParentObject, $strControlId);
        $this->calDate->Name = QApplication::Translate('Date');
        //$this->calDate->DateTimePickerType = QDateTimePickerType::Date;
        if ($this->blnEditMode)
            $this->calDate->DateTime = $this->objCompetitor->Date;
        else { //new
            $DefualtDate = new QDateTime();
            $DefualtDate->SetDate(date("Y"), date("m"), date("d"));
            $this->calDate->DateTime= $DefualtDate;
        }
        return $this->calDate;
    }
    public function SaveCompetitor() {
        try {
            //Prepare data for Record Info
            $this->dttTime = new QDateTime();
            $this->dttTime->setDate (date("Y"), date("m"), date("d"));
            $this->dttTime->setTime (date("H"), date("i"), date("s"));
            //Get Current user
            $CurrentUser = $_SESSION['User']['Id'];
            //Should eUser
            $Euser = $CurrentUser;

            // Update any fields for controls that have been created
            $this->objCompetitor->SchoolId = $_SESSION['Org']->Id;
            $this->objCompetitor->Euser = $Euser;

            if (strlen($this->txtACompetitor->Text) > 0) {
                $objOrg=Org::LoadByName($this->txtACompetitor->Text);
                $this->objCompetitor->CompetitorId = $objOrg->Id;
            }

            if ($this->calDate)  $this->objCompetitor->Date = $this->calDate->DateTime;
            if ($this->txtNotes) $this->objCompetitor->Notes = $this->txtNotes->Text;


            if ($this->blnEditMode) {
                //*** Update
                $this->objCompetitor->UpdateBy   = $CurrentUser;
                $this->objCompetitor->UpdateDate = $this->dttTime;
            }
            else {
                //**** New
                $this->objCompetitor->CreateBy   = $CurrentUser;
                $this->objCompetitor->CreateDate = $this->dttTime;
            }
            $this->objCompetitor->Save();
            //$this->calDate->Text ="";
            $this->txtNotes->Text ="";
            $this->txtACompetitor->Text ="";
            // Finally, update any ManyToManyReferences (if any)
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }

}
?>